package com.gitee.mp.domain.condition;

import com.gitee.mp.infra.constants.LogicalOperator;
import com.gitee.mp.infra.constants.MilvusPlusConstants;

import java.util.Objects;
import java.util.function.UnaryOperator;

/**
 * @author hongda.li
 */
public record Condition(String fieldName,
                        String operator,
                        Object value,
                        LogicalOperator linkOperator) {

    /**
     * 组合条件表达式
     *
     * @param transformer 字段替换函数
     * @return 表达式内容
     */
    public String combine(UnaryOperator<String> transformer) {
        String target = transformer.apply(fieldName);
        Objects.requireNonNull(target);
        return String.format(MilvusPlusConstants.CONDITION_TEMPLATE, target, operator, value);
    }
}
